package com.lfx.concurrent.phaser;

import java.util.Random;
import java.util.concurrent.Phaser;

/**
 * @author 李逢喜
 * create 2021/8/4
 */
public class CountDownLatchWorker {


    public static void main(String[] args) {

        Phaser phaser=new Phaser(10);
        Random random=new Random();
        for (int i = 0; i < 10; i++) {

            new Thread("线程"+i){
                @Override
                public void run() {
                    try {
                        System.out.println(getName() + " - 开始运行");
                        Thread.sleep(random.nextInt(1000));
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(getName() + "运行结束");
                    phaser.arrive();
                }
            }.start();
        }
        System.out.println("线程启动完毕");
        phaser.awaitAdvance(phaser.getPhase());
        System.out.println("主线程即将退出");

    }
}
